package com.leige.utils.tool;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DateFormatUtils {
	private static final Log logger = LogFactory.getLog(DateFormatUtils.class);
	private static DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
	@Resource(name="dateFormat")
	public void setDateFormat(DateFormat dateFormat) {
		DateFormatUtils.dateFormat = dateFormat;
	}
	public static String format(Date date){
		return dateFormat.format(date);
	}
	public static  Date parse(String source){
		try {
			return dateFormat.parse(source);
		} catch (ParseException e) {
			logger.error("日期类型转化失败，需要的日期格式如"+dateFormat.format(new Date()) ,e);
			return null;
		}
	}
}
